package com.nf.controller.manage;

import com.google.gson.Gson;
import com.nf.controller.BaseServlet;
import com.nf.dao.HallInfoDao;
import com.nf.dao.impl.HallInfoDaoImpl;
import com.nf.entity.HallInfo;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * 编写servlet，实现影厅的添加
 */
@WebServlet("/api/HallAddServlet.do")
public class HallAddServlet extends BaseServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String hallName=req.getParameter("hallName");
        String hallType=req.getParameter("hallType");
        int hallNumber= Integer.parseInt(req.getParameter("hallNumber"));
        String rowsCols=req.getParameter("rowsCols");

        HallInfo hall=new HallInfo();
        hall.setHallName(hallName);
        hall.setHallType(hallType);
        hall.setHallNumber(hallNumber);
        hall.setRowsCols(rowsCols);

        HallInfoDao dao=new HallInfoDaoImpl();
        int r= dao.add(hall);

        resp.setContentType("application/json;charset=utf-8");
        PrintWriter out = resp.getWriter();

        if(r==1){
            out.print(new Gson().toJson(successJson("添加成功")));
        }else {
            out.print(new Gson().toJson(errorJson("添加失败")));
        }

        out.flush();
        out.close();

    }
}
